package lagou.model3.test1;

public class CharacterString {
    private int smallCount;
    private int bigCount;
    private int numCount;
    private int otherCount;

    /**
     * 统计各个字符个数
     * @param string
     */
    public void calculateNum(String string) {
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                bigCount++;
                System.out.println("发现大写字母" + c + ",目前大写字母有" + bigCount + "个");
            } else if (c >= 'a' && c <= 'z') {
                smallCount++;
                System.out.println("发现小写字母" + c + ",目前小写字母有" + smallCount + "个");
            } else if (c >= '0' && c <= '9') {
                numCount++;
                System.out.println("发现数字字符" + c + ",目前数字字符有" + numCount + "个");
            } else {
                otherCount++;
                System.out.println("发现其它字符" + c + ",目前其它字符有" + otherCount + "个");
            }
        }
    }

    /**
     * 返回打印结果
     * @param string
     */
    public void getNum(String string) {
        System.out.println("字符串" + string +
                "中小写字母有" + smallCount +
                "个, 大写字母有" + bigCount +
                "个, 数字字符有" + numCount +
                "个, 其它字符有" + otherCount + "个"
        );
    }
}
